package com.itheima.datastructure.stack;

/**
 * 双栈模拟队列
 *
 * <ul>
 *     <li>调用 push、pop 等方法的次数最多 100</li>
 * </ul>
 */
public class E04Leetcode23201 {

    //暂存栈
    ArrayStack<Integer> cache = new ArrayStack<>(100);
    //存储栈
    ArrayStack<Integer> store = new ArrayStack<>(100);

    public void push(int x) {
        while (!store.isEmpty()) {
            cache.push(store.pop());
        }
        store.push(x);
        while (!cache.isEmpty()) {
            store.push(cache.pop());
        }
    }

    public int pop() { // 从对列头移除
        return store.pop();
    }

    public int peek() { // 从对列头获取
        return store.peek();
    }

    public boolean empty() {
        return store.isEmpty();
    }

    public static void main(String[] args) {
        E04Leetcode23201 queue = new E04Leetcode23201();
        queue.push(1);
        queue.push(2);
        queue.push(3);
        queue.push(4);

        System.out.println(queue.pop());
        queue.push(5);
        System.out.println(queue.pop());
        while (!queue.empty()){
            System.out.print(queue.pop() +"   ");
        }


    }

}
